﻿using System;
using System.Linq;
using ApprovalTests;
using ApprovalTests.Reporters;
using License;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Registration.Test.TestUtils;

namespace Registration.Test
{
  [TestClass]
  [UseReporter(typeof(DiffReporter))]
  public class LicenseTest
  {
    [TestMethod]
    public void TestLicense()
    {
      Driver p = new Driver
      {
        FirstName = "Jason",
        Surname = "malinowski",
        ID = "JM5555555",
        ExpirationDate = new DateTime(2015, 5, 5),
        Address = "123 Fake Street, Redmond, WA 98052",
        Gender = Gender.Male,
        Height = 2,
        Weight = 80,
        Eyes = Eyes.Brown,
        PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
      };

      ApprovalTests.Wpf.Approvals.Approve(() => new DriversLicense(p));
    }

    [TestMethod]
    public void TestSingleNameFails()
    {
      Driver p = new Driver
      {
        FirstName = "Madonna",
        ID = "JM5555555",
      };

      ApprovalTests.Wpf.Approvals.Approve(() => new DriversLicense(p));
    }

    [TestMethod]
    public void TestLicenseSliced()
    {
      Driver p = new Driver
      {
        FirstName = "Jason",
        Surname = "Malinowski",
        ID = "JM5555555",
        ExpirationDate = new DateTime(2015, 5, 5),
        Address = "123 Fake Street, Redmond, WA 98052",
        Gender = Gender.Male,
        Height = 2,
        Weight = 80,
        Eyes = Eyes.Brown,
        PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
      };

      ApprovalTests.Wpf.Approvals.Approve(() => new DriversLicense(p).Load("Jason", "Malinowski", new[] { p }));
    }

    [TestMethod]
    public void TestDatabaseEcho()
    {
      using (Database database = new Database())
      {
        Assert.AreEqual(42, database.ExecuteQuery<int>("SELECT 42").Single());
      }
    }

    [TestMethod]
    public void TestLicenseFromDatabase()
    {
      DatabaseUtils.Delay = 0;
      DatabaseUtils.InitializeDatabase();
      ApprovalTests.Wpf.Approvals.Approve(() => new DriversLicense().Load("Jason", "Malinowski"));
    }
  }
}
